package com.jit.BluetoothKey.utils;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by Administrator on 2018/2/7.
 * 用户偏好操作工具类，用于存储用户本地信息
 */

public class SharedPreferencesUtil {
    public static void setString(Context context, String key, String value) {
        SharedPreferences sp = context.getSharedPreferences(UserFiled.USER_ABOUT, Context.MODE_PRIVATE);
        SharedPreferences.Editor edit = sp.edit();
        edit.putString(key, value);
        edit.commit();
    }

    public static String getString(Context context, String name){
        SharedPreferences sp = context.getSharedPreferences(UserFiled.USER_ABOUT, Context.MODE_PRIVATE);
        String string = sp.getString(name, "");
        return string;
    }

    public static void setIsLogin(Context context, String key, Boolean isLogin){
        SharedPreferences sp = context.getSharedPreferences(UserFiled.USER_ABOUT, Context.MODE_PRIVATE);
        SharedPreferences.Editor edit = sp.edit();
        edit.putBoolean(key,isLogin);
        edit.commit();
    }
    public static boolean getIsLogin(Context context, String key){
        SharedPreferences sp = context.getSharedPreferences(UserFiled.USER_ABOUT, Context.MODE_PRIVATE);
        boolean aBoolean = sp.getBoolean(key, false);
        return aBoolean;
    }
    public static boolean getBoolean(Context context, String key){
        SharedPreferences sp = context.getSharedPreferences(UserFiled.USER_ABOUT, Context.MODE_PRIVATE);
        boolean aBoolean = sp.getBoolean(key, false);
        return aBoolean;
    }

    public static void setBoolean(Context context, String key, Boolean isLogin){
        SharedPreferences sp = context.getSharedPreferences(UserFiled.USER_ABOUT, Context.MODE_PRIVATE);
        SharedPreferences.Editor edit = sp.edit();
        edit.putBoolean(key,isLogin);
        edit.commit();
    }
}
